package one1;

import java.util.Arrays;


//T是表示泛型，创建一个数组可以保存任意类型的数据
class Array<T> {
    public Object[] array = new Object[10];

    public void setArray(int pos, T val) {
        array[pos] = val;
    }

    public T getArray(int pos) {
        return (T) array[pos];
    }

    //@Override
    public String toString() {
        return "Array{" +
                "array=" + Arrays.toString(array) +
                '}';
    }
}

public class Test1 {
    public static void main(String[] args) {
        Array<Integer> array1 = new Array<Integer>();
        Array<String> array2 = new Array<String>();
        for (int i = 0; i < 10; i++) {
            array1.setArray(i, i);
        }
        ;
        System.out.println(array1.toString());


        array2.setArray(0, "hello");
        array2.setArray(1, "world");
        System.out.println(array2.getArray(0) + " " + array2.getArray(1));
    }


   /* public static void main1(String[] args) {
        Array array = new Array();
        array.setArray(0, 1);
        array.setArray(1, "hello");
        array.setArray(2, 3);
        System.out.println(array.getArray(0));
        System.out.println(array.getArray(1));
        System.out.println(array.getArray(2));


    }*/

}
